{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">爱心苑列表</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <div class="temTable layui-fluid">
                <div class="temTable-member-list layui-fluid">
                    申请人：
                    <div class="layui-inline">
                        <input type="text" class="layui-input" id="mobile" name=mobile" placeholder="模糊查询输入用户名/手机号">
                    </div>
                    审核人：
                    <div class="layui-inline">
                        <input type="text" class="layui-input" id="admin" name=admin" placeholder="模糊查询输入用户名/手机号">
                    </div>
                    申请时间：
                    <div class="layui-inline">
                        <input type="text" class="layui-input" id="addtime" name="addtime" >
                    </div>
                    状态:
                    <div class="layui-inline">
                        <select class="layui-form-select" id="status" name="status">
                            <option value="">请选择</option>
                            <option value="-1">审核未通过</option>
                            <option value="0">未审核</option>
                            <option value="1">未认领</option>
                            <option value="2">已认领</option>
                            <option value="3">已完成</option>
                        </select>
                    </div>
                    <button class="layui-btn search" data-type="reload">搜索</button>
                </div>
            </div>
            <table class="layui-hide" id="table" lay-filter="table"></table>

            <script type="text/html" id="barTool">
                <a class="layui-btn layui-btn-xs" lay-event="info">详情</a>
                {{#  if(d.status == 0){ }}
                    <a class="layui-btn layui-btn-xs" lay-event="pass">通过</a>
                    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="refuse">拒绝</a>
                {{#  } else if(d.status == 1) { }}
                    <a class="layui-btn layui-btn-xs layui-btn-danger layui-btn-disabled">不可操作</a>
                {{#  } else if(d.status == 2) { }}
                    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="unlock">解绑</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="finish">归档</a>
                {{#  } else if(d.status == 3) { }}
                <a class="layui-btn layui-btn-xs layui-btn-danger layui-btn-disabled">不可操作</a>
                {{#  } else if(d.status == -1) { }}
                <a class="layui-btn layui-btn-xs layui-btn-danger layui-btn-disabled">不可操作</a>
                {{#  } }}

            </script>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.use(['table','laydate','form'], function() {
        var table = layui.table,
            $ = layui.$
            ,form = layui.form
            ,laydate = layui.laydate;

        //日期时间范围
        laydate.render({
            elem: '#addtime'
            ,type: 'datetime'
            ,range: true
        });

        table.render({
            elem: '#table',
            toolbar: '#toolbarDemo',
            url: '{:url("admin/loveList/index")}',
            cols: [
                [
                    { field: 'id', width: 60, title: 'ID',fixed:true},
                    { field: 'member', width: 120, title: '申请人账号',fixed:true},
                    { field: 'helper', width: 120, title: '帮助人账号',fixed:true},
                    { field: 'type', width: 100, title: '申请类型',fixed:true},
                    { field: 'status_name', width: 100, title: '申请状态',fixed:true},
                    { field: 'realname', width: 120, title: '求助人姓名'},
                    { field: 'help_name', width: 120, title: '帮助人姓名'},
                    { field: 'danwei', width: 200, title: '求助人单位' },
                    { field: 'help_danwei', width: 200, title: '帮助人单位' },
                    { field: 'rudang_date', width: 120, title: '求助人入党时间' },
                    { field: 'help_bron', width: 120, title: '帮助人出生时间' },
                    { field: 'sex', width: 60, title: '求助人性别' },
                    { field: 'help_sex', width: 60, title: '帮助人性别' },
                    { field: 'mobile', width: 120, title: '求助人联系方式' },
                    { field: 'help_mobile', width: 120, title: '帮助人联系方式' },
                    { field: 'channel', width: 200, title: '求助获取帮助渠道' },
                    { field: 'help_political', width: 200, title: '帮助人政治面貌' },
                    { field: 'help_political_info', width: 200, title: '帮助人政治面貌详情' },
                    { field: 'type_name', width: 60, title: '求助需求类型' },
                    { field: 'info', width: 300, title: '求助人申请详情' },
                    { field: 'wish_info', width: 300, title: '心愿项目' },
                    { field: 'help_info', width: 300, title: '帮助人申请详情' },
                    { field: 'create_time', width: 200, title: '申请时间' },
                    { field: 'exame_user', width: 200, title: '审核人' },
                    { field: 'exame_time', width: 200, title: '审核时间' },
                    { field: 'take_time', width: 200, title: '认领时间' },
                    { fixed: 'right', width: 160, title: '操作', toolbar: '#barTool' }
                ]
            ],
            id: 'testReload',
            page: {}
        });

        //监听行工具事件
        table.on('tool(table)', function(obj) {
            var data = obj.data;
            //console.log(obj);
            if (obj.event === 'pass') {
                layer.confirm('确定通过这条爱心苑？', { icon: 3, title: '提示' }, function(index) {
                    layer.close(index);
                    $.post('{:url("admin/loveList/pass")}', { 'id': data.id }, function(data) {
                        if (data.code == 1) {
                            if (data.url) {
                                layer.msg(data.msg + ' 页面即将自动跳转~');
                            } else {
                                layer.msg(data.msg);
                            }
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                } else {
                                    location.reload();
                                }
                            }, 1500);
                        } else {
                            layer.msg(data.msg);
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                }
                            }, 1500);
                        }

                    });
                });
            }else if (obj.event === 'info') {
                window.open('{:url("admin/loveList/info")}' + "?id=" + data.id, '_self')
            }else if(obj.event === 'refuse'){
                window.open('{:url("admin/loveList/fail")}' + "?id=" + data.id, '_self')
                // layer.open({
                //     type: 2,
                //     title: '拒绝申请',
                //     shadeClose: true,
                //     shade: 0.8,
                //     area: ['50%', '80%'],
                //     content: '/admin/love_list/fail?id='+data.id    //直接显示某个页面的内容
                // });
            }else if(obj.event === 'finish'){
                layer.confirm('确定完成这条爱心苑？', { icon: 3, title: '提示' }, function(index) {
                    layer.close(index);
                    $.post('{:url("admin/loveList/finish")}', { 'id': data.id }, function(data) {
                        if (data.code == 1) {
                            if (data.url) {
                                layer.msg(data.msg + ' 页面即将自动跳转~');
                            } else {
                                layer.msg(data.msg);
                            }
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                } else {
                                    location.reload();
                                }
                            }, 1500);
                        } else {
                            layer.msg(data.msg);
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                }
                            }, 1500);
                        }

                    });
                });
            }else if(obj.event === 'unlock'){
                layer.confirm('确定解绑？', { icon: 3, title: '提示' }, function(index) {
                    layer.close(index);
                    $.post('{:url("admin/loveList/unlock")}', { 'id': data.id }, function(data) {
                        if (data.code == 1) {
                            if (data.url) {
                                layer.msg(data.msg + ' 页面即将自动跳转~');
                            } else {
                                layer.msg(data.msg);
                            }
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                } else {
                                    location.reload();
                                }
                            }, 1500);
                        } else {
                            layer.msg(data.msg);
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                }
                            }, 1500);
                        }

                    });
                });
            }
        });


        var $ = layui.$, active = {
            reload: function () {
                var mobile = $("#mobile").val();
                var admin = $("#admin").val();
                var status = $("#status").val();
                var time = $("#addtime").val();
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
//                        key: {
                        mobile: mobile,
                        admin: admin,
                        status: status,
                        time: time
//                        }
                    }
                });
            }
        };
        $('.temTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
{/block}